<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div>
    <h1>拷贝继承</h1>
    <strong>把父对象的所有属性和方法，拷贝进子对象</strong>
    <p>将父对象的prototype对象中的属性，一一拷贝给Child对象的prototype对象中</p>
  </div>
  <script>
    function Parent() {
    }
    Parent.prototype.money = 100000
    Parent.prototype.head = 1
    Parent.prototype.say = function () {
      alert('虽然我只有一个头，但我有' + this.money + '块')
    }

    function Child(name, age) {
      this.name = name
      this.age = age
    }

    function extend(Son, Father) {
      var fa = Father.prototype
      var son = Son.prototype
      for (var i in fa) {
        son[i] = fa[i]
      }
    }

    extend(Child, Parent)
    var son = new Child('jiffy', 22)
    alert(Child.prototype.constructor)
    alert(Parent.prototype.constructor)
    son.say()

  </script>
</body>

</html>